package org.example.custom;

import org.example.util.JDBCUtil;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;

public class Hello03Select {
    public static void main(String[] args) throws SQLException {
        //获取数据库连接
        Connection connection = JDBCUtil.getConnection();
        //获取SQL语句
        String sql = "select * from yjxxt.user";
        PreparedStatement statement = connection.prepareStatement(sql);
        //执行SQL语句
        ResultSet resultSet = statement.executeQuery();
        //遍历结果集合
        while (resultSet.next()) {
            //获取数据
            int id = resultSet.getInt("id");
            String uname = resultSet.getString("uname");
            String passwd = resultSet.getString("passwd");
            System.out.println("Hello01Insert.main[" + id + "][" + uname + "][" + passwd + "]");
        }
        //关闭连接
        JDBCUtil.closeAll(connection, statement, resultSet);
    }
}